Release 10.1A: OpenEdge Development:
Progress 4GL Reference


NEW statement

Creates an object instance of a class, and assigns an object reference for the instance to a variable. You access a class object instance, as well as its data members and methods, using its associated object reference variable.

Note: The application is responsible for deleting the class object instance using the DELETE OBJECT statement. If the variable that contains the object reference for the instance goes out of scope before you delete the object instance, the instance remains in memory without an object reference.

Syntax\

object-reference = NEW type-name ( [ parameter [, parameter ] ... ] ) 
[ NO-ERROR ]. 

object-reference

The name of the variable to contain the object reference for the new class object instance. You use this object reference variable to access the class object instance, and its PUBLIC data members and methods.

To define an object reference variable for a class object instance, use the DEFINE VARIABLE statement with the CLASS option. For more information, see the DEFINE VARIABLE statement reference entry in this book.

type-name

A character string that specifies the type name of the class. Specify a class type name using the package.class-name syntax as described in the Type-name syntax reference entry in this book.

The class-name must specify one of the following:

( parameter [, parameter ] ... )

Specifies one or more parameters to pass to the constructor method defined for the class. You must provide the parameters identified by the constructor method, and the parameters must match with respect to the number, data type, and mode.

For the parameter passing syntax, see the Parameter passing syntax reference entry in this book.

For information about defining a constructor method for a class, see the CONSTRUCTOR statement reference entry in this book.

NO-ERROR

Suppresses any errors that occur during the invocation of the constructor for the class, or any class in the inherited class hierarchy, while attempting to create the class object instance or its inherited class hierarchy. For example:

Example

The following example shows the definition of a variable to contain the object reference for a new class object instance:

DEFINE VARIABLE myCustObj AS CLASS acme.myObjs.CustObj NO-UNDO. 
myCustObj = NEW acme.myObjs.CustObj ( ).  

Notes

See also

CAST function, CLASS statement, CONSTRUCTOR statement, DEFINE VARIABLE statement, FIRST-OBJECT attribute, FUNCTION statement, LAST-OBJECT attribute, METHOD statement


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095